Innan du går igenom avbuggningssmärtan, använd testramverket för att kontrollera om standardtesterna fungerar korrekt. Om inte så kanske det kan bero på en trasig installation.
Before you go through the pain of debugging use the Test framework to check if the standard tests work properly. If they do not run complete there is possibly a broken installation.
Avbuggningen av FreeCAD stöds av en del interna mekanismer. Kommandoradsversionen av FreeCAD erbjuder alternativ för avbuggningsstöd:
The debugging of FreeCAD is supported by a few internal mechanisms. The command line version of FreeCAD provides some options for debugging support.
These are the currently recognized options in FreeCAD 0.19:
Generic options:
-v [ --version ] Prints version string -h [ --help ] Prints help message -c [ --console ] Starts in console mode --response-file arg Can be specified with '@name', too --dump-config Dumps configuration --get-config arg Prints the value of the requested configuration key
Configuration:
-l [ --write-log ] Writes a log file to: $HOME/.local/share/FreeCAD/FreeCAD.log (Linux) $HOME/Library/Application\ Support/FreeCAD/FreeCAD.log (macOS) %APPDATA%\FreeCAD\FreeCAD.log (Windows) --log-file arg Unlike to --write-log this allows to log to an arbitrary file -u [ --user-cfg ] arg User config file to load/save user settings -s [ --system-cfg ] arg System config file to load/save system settings -t [ --run-test ] arg Test case - or 0 for all -M [ --module-path ] arg Additional module paths -P [ --python-path ] arg Additional Python paths --single-instance Allow to run a single instance of the application
If you are running a version of FreeCAD from the bleeding edge of the development curve, it may "crash". You can help solve such problems by providing the developers with a "backtrace". To do this, you need to be running a "debug build" of the software. "Debug build" is a parameter that is set at compile time, so you'll either need to compile FreeCAD yourself, or obtain a pre-compiled "debug" version.
Linux Debugging →
Prerequisites:
Steps: Enter the following in your terminal window:
Find FreeCAD binary on your system:
$ whereis freecad
freecad: /usr/local/freecad <--- for example
$ cd /usr/local/freecad/bin
$ gdb FreeCAD
GNUdebugger will output some initializing information. The (gdb) shows GNUDebugger is running in the terminal, now input:
(gdb) handle SIG33 noprint nostop
(gdb) run
FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window:
(gdb) bt
This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report.
(gdb) bt full
Print the values of the local variables also. This can be combined with a number to limit the number of frames shown.
macOS Debugging →
Prerequisites:
Steps: Enter the following in your terminal window:
$ cd FreeCAD/bin
$ lldb FreeCAD
LLDB will output some initializing information. The (lldb) shows the debugger is running in the terminal, now input:
(lldb) run
FreeCAD will now start up. Perform the steps that cause FreeCAD to crash or freeze, then enter in the terminal window:
(lldb) bt
This will generate a lengthy listing of exactly what the program was doing when it crashed or froze. Include this with your problem report.
(Applicable to Linux and macOS)
Sometimes it's helpful to understand what libraries FreeCAD is loading, specifically if there are multiple libraries being loaded of the same name but different versions (version collision). In order to see which libraries are loaded by FreeCAD when it crashes you should open a terminal and run it in the debugger. In a second terminal window, find out the process id of FreeCAD:
ps -A | grep FreeCAD
Use the returned id and pass it to lsof
:
lsof -p process_id
This prints a long list of loaded resources. So for example, if trying to ascertain if more than one Coin3d library versions is loaded, scroll through the list or search directly for Coin in the output:
lsof -p process_id | grep Coin
For a more modern approach to debugging Python, see these posts:
winpdb Debugging →
Here is an example of using Winpdb inside FreeCAD:
We need the Python debugger: Winpdb. If you do not have it installed, on Ubuntu/Debian install it with:
sudo apt-get install winpdb
Now lets setup the debugger.
Now we will run a test Python script in FreeCAD step by step.
import rpdb2
rpdb2.start_embedded_debugger("test")
import FreeCAD
import Part
import Draft
print "hello"
print "hello"
import Draft
points=[FreeCAD.Vector(-3.0,-1.0,0.0),FreeCAD.Vector(-2.0,0.0,0.0)]
Draft.makeWire(points,closed=False,face=False,support=None)
VS Code Debugging →
Prerequisites:
# In a cmd window that has a path to you local Python 3:
pip install ptvsd
# Then if your Python is installed in C:\Users\<userid>\AppData\Local\Programs\Python\Python37
# and your FreeCAD is installed in C:\freecad\bin
xcopy "C:\Users\<userid>\AppData\Local\Programs\Python\Python37\Lib\site-packages\ptvsd" "C:\freecad\bin\Lib\site-packages\ptvsd"
Visual Studio Code documentation for remote debugging
Steps:
import ptvsd
print("Waiting for debugger attach")
# 5678 is the default attach port in the VS Code debug configurations
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)
ptvsd.wait_for_attach()
"configurations": [ { "name": "Python: Attacher", "type": "python", "request": "attach", "port": 5678, "host": "localhost", "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "." } ] },
from sys import path
sys.path.append('/path/to/site-packages')
Where the path is to the directory where ptvsd was installed.
In the Mac package it is /Applications/FreeCAD.App/Contents/Resources/bin/python.
You can locate it on your system by typing
import sys
print(sys.executable)
into FreeCAD's Python console.
LiClipse Debugging →
> ./your location/FreeCAD_xxx.AppImage --appimage-extract
> cd squashfs-root/
squashfs-root> ./usr/bin/freecadcmd
your loc/squashfs-root/usr/bin/python
.pydevd.py
in your liclipse installation.
your location/liclipse/plugins/org.python.pydev.xx/pysrc
.import sys; sys.path.append("path ending with /pysrc")
import pydevd; pydevd.settrace()
squashfs-root> ./usr/bin/freecad
pydevd.settrace()
trigger) from within freecad, as you would normally do.See the main article about Pyzo.
For developers needing to dig deeper in to the OpenCasCade kernel, user @abdullah has created a thread orientation discussing how to do so.